package org.classdef.analyzer.info.attribute;

import org.classdef.analyzer.info.ClassDef;
import org.classdef.analyzer.info.constant.ConstantInfo;

/**
 * 
 * 属性描述信息
 *
 */
public class AttributeInfo {
	// index of the constant pool
	private short attributeNameIndex;
	private int attributeLength;
	private byte[] info;
	
	protected ClassDef def;

	public AttributeInfo(short attributeNameIndex, int attributeLength,
			byte[] info) {
		this.attributeNameIndex = attributeNameIndex;
		this.attributeLength = attributeLength;
		this.info = info;
	}

	/**
	 * @return attributeNameIndex
	 */
	public short getAttributeNameIndex() {
		return attributeNameIndex;
	}

	/**
	 * @return attributeLength
	 */
	public int getAttributeLength() {
		return attributeLength;
	}

	/**
	 * @return info
	 */
	public byte[] getInfo() {
		return info;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		sb.append("\"attributeNameIndex\":").append(attributeNameIndex);
		sb.append(",\"name\":\"").append(getConst(attributeNameIndex).getValue()).append("\"");
		sb.append(",\"attributeLength\":").append(attributeLength);
//		sb.append(",\"info\":\"").append(new String(info)).append("\"");
		sb.append("}");
		return sb.toString();
	}
	
	private ConstantInfo getConst(int index){
		return def.getConstantPool().get(index);
	}
}